package com.example.base.tools

/**  emoji 表情工具类  **/
object EmojiTool {

    /**  检测来源字符串是否包含 emoji 表情  **/
    fun containsEmoji(source: String): Boolean {
        val length = source.length
        for (i in 0 until length) {
            if (!isEmojiChar(source.codePointAt(i))) {
                return true
            }
        }

        return false
    }

    /**  是否为 emoji 表情字符  **/
    private fun isEmojiChar(codePoint: Int) =
        (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA) || (codePoint == 0xD)
                || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD))
                || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))

}